package nit.wave.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nit.wave.model.Biaobai;
import nit.wave.service.BiaobaiService;

public class addBiaobaiServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 将请求、响应的编码均设置为UTF-8（防止中文乱码）
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		String nikeName = request.getParameter("nikeName");
		String content = request.getParameter("content");
		int type = Integer.parseInt(request.getParameter("type"));
		SimpleDateFormat vTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String VerifyTime = vTime.format(new Date());
		Biaobai biaobai = new Biaobai(0, nikeName, content, VerifyTime, type, 0, "");
		BiaobaiService biaobaiService = new BiaobaiService();
		biaobaiService.addBiaobai(biaobai);
		PrintWriter out = response.getWriter();
		out.print("success");
		out.close();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

}
